﻿using System;
using BaseUdp = CzfUDP.CzfUDPClient;

namespace CzfSDK
{
	public class CzfUdpClient : CzfNetClient
	{
		public BaseUdp baseUdp;

		public CzfUdpClient(BaseUdp baseUdp){
			this.baseUdp = baseUdp;
			this.lastRecive = DateTime.Now;
			this.remoteEndPoint = baseUdp.remote_end.ToString ();
			baseUdp.OnRecive += Recive;
			baseUdp.OnClose += (obj) => {
				if(OnClose != null)
					OnClose (this);
			};
			baseUdp.OnDebug += CzfLog.Info;
		}

		public override void BeginRecive ()
		{
			baseUdp.Open ();
		}

		public override void Send (byte[] bytes)
		{
			baseUdp.Send (bytes);
		}

		public override void Close ()
		{
			baseUdp.Close ();
		}

		void Recive (BaseUdp p1, byte[] data)
		{
			this.lastRecive = DateTime.Now;
			if(OnRecive != null)
				OnRecive (this, data);
		}
	}
}

